package com.wanaofu.service;

import static org.testng.AssertJUnit.assertTrue;

import java.math.BigDecimal;

import javax.annotation.Resource;

import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.annotations.Test;

import com.wanaofu.model.ProductInfo;
import com.wanaofu.model.UserInfo;
import com.wanaofu.model.Warehouse;

@ContextConfiguration("classpath:applicationContext.xml")
public class DataInit extends AbstractTransactionalTestNGSpringContextTests {
	@Resource
	private WarehouseService warehouseService;
	
	@Resource
	private ProductService productService;
	
	@Test(groups= {"init-data"})
	@Rollback(false)
	public void initWarehouse() {
		String id = "W001" ;
		Warehouse user = new Warehouse(id,"A001","S001","F001");
		warehouseService.saveWarehouse(user);
		
		Warehouse user2 = new Warehouse(id,"A002","S001","F001");
		warehouseService.saveWarehouse(user2);
		
		assertTrue(warehouseService.exitsWarehouseByWareCode(id));

	}

	@Test(groups= {"init-data"})
	@Rollback(false)
	public void initProductInfo() {
		String code = "P001" ;
		ProductInfo p = new ProductInfo(code,"羊鞭") ;
		p.setPicture("yang_bian.jpg") ;
		productService.createProductInfo(p);
		assertTrue(productService.exitsProduct(code));
		
		ProductInfo p2 = new ProductInfo("P002","羊蝎子","691200011","精品羊蝎子",new BigDecimal("15.5")) ;
		p2.setPicture("yang_xie_zhi.jpg") ;
		productService.createProductInfo(p2);
		assertTrue(productService.exitsProduct("P002"));
	}
	
	@Test(groups= {"init-data"})
	@Rollback(false)
	public void initUserInfo() {
    	warehouseService.saveUserInfo(new UserInfo("U001","Jianken","1234"));
    	assertTrue(warehouseService.getUserInfoByCode("U001")==null?false:true);
	}
	

	
}
